package com.lwz.oss.controller;

import com.lwz.oss.service.OssService;
import com.lwz.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Lw中
 * @date 2020/11/10 16:23
 */

@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * 此方法用于将上传到OSS上的图片的url返回给前端，在点击保存讲师数据按钮之后，
     * 通过service-edu模块对图片url进行保存
     * @param file
     * @return
     */
    @PostMapping
    public R uploadOssFile(MultipartFile file) {
        String url = ossService.uploadFileAvatar(file);
        return R.ok().data("url", url);
    }

}
